<?php
/**
 * User: zibuyu
 * Date: 2015/8/8
 * link    http://www.ibuyu.cn
 */
class goods{
    function getOne($id){
        $sql='select * from __goods ';
    }
    static function getPhoto($id){
        $sql='select id,img from __goods_photo where goods_id='.$id.' order by id asc';
        return db::get_all($sql);
    }
    static function goods_attribute($id){
        $sql='select attribute_id,attribute_value,model_id,`order` from __goods_attribute where goods_id='.$id;
        return db::get_all($sql);
    }
    function getList($cat_id,$page=1,$size=10,$order='g.sort asc,g.id desc'){
        $where='where 1';
        if($cat_id)$where.=' and t.category_id='.$cat_id;
        $sql='select g.* from __goods g left join __category_extend t on t.goods_id=g.id '.$where.' group by g.id order by '.$order.' limit '.(($page-1)*$size).','.$size;
        $res=db::_query($sql);
        $result=array();
        while($ob=db::_object($res)){
            $ob->url=U('goods',array('type'=>'goods','id'=>$ob->id));
            $result[]=$ob;
        }
        return $result;
    }
}